<template>
	<view class="container">
		<view class="list">
			<view class="listin" v-for="(item,index) in list" :key="index"
				:style="active==index?'border:#1890FF 2px solid':''" @click="choose(index)">
				<view class="title">
					<text>运单编号：{{item.waybill_sn}}</text>
					<text style="color: #1890FF;font-weight: 400;">
						{{statusText(item.status)}}
					</text>
				</view>
				<view class="body">
					<text>增加金额：{{item.amount || ''}}</text>
					<text>司机：{{item.driver_name || ''}}</text>
					<text>车牌号：{{item.car_plate || ''}}</text>
					<text>司机手机号：{{item.driver_mobile || ''}}</text>
					<text>申请时间：{{item.createtime || ''}}</text>
					<text>申请原因：{{item.remark || ''}}</text>
					<text v-if="item.refuse_remark">拒绝原因：{{item.refuse_remark || ''}}</text>
				</view>
				<view class="btn-box" v-if="item.status ==0">
					<view class="btn-area">
						<button size="mini" type="primary" @click="examine(item)">审核</button>
					</view>
				</view>
			</view>
		</view>
		<view class="none" v-if="list==''">
			<image src="../../static/img/none.png" mode=""></image>
			<text>暂无信息</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				active: null,
				chooseindex: null,
				listStyle: {
					border: "#1890FF 2px solid"
				},
				page: 1,
				list: [],
				examineStatus: 1,
				examineId: 0,
				examineRefuseRemark: '',
				status_text_array: ['待审核', '通过','拒绝'],
				
			};
		},
		onShow() {
			this.getlist()
		},
		onReachBottom() {
			this.page++;
			this.getlist();
		},
		methods: {
			getlist() {
				let data = {
					page: this.page,
				}
				this.$freightagainlists(data).then(res => {
					this.list = [...this.list, ...res.data.data]
				})
			},
			examine(data) {
				console.log('data: ',data);
				
				uni.showModal({
					title: '增加车费审核',
					content: '',
					cancelText: '通过',
					confirmText: '拒绝',
					editable: true,
					placeholderText: '拒绝原因',
					confirmColor:'#DD524D',
					cancelColor:'#1aad19',
					success:  (res) => {
						if (res.confirm) {
							 
							this.examineStatus = 2;
						} else if (res.cancel) {
							 
							this.examineStatus = 1;
						}
						console.log('res: ',res);
						let {id} = data;
						this.examineId = id ?? 0;
						this.examineRefuseRemark = res.content ?? '' ;
						this.examineHandler();
					}
				});
				
				
			},
			choose(index){
			},
			examineHandler(){
				let data = {
					id: this.examineId,
					status: this.examineStatus,
					refuse_remark: this.examineRefuseRemark,
				}
				console.log('examineHandlerdata: ',data);
				this.$freightagainexamine(data).then(res=>{
					this.$toast(res.msg)
					this.page = 1;
					this.list = [];
					this.getlist()
				})
			},
			statusText(status) {
				let status_text =  this.status_text_array[status];
				return status_text;
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.container {
		.list {
			padding: 20rpx;

			.listin {
				padding: 30rpx;
				background-color: #fff;
				box-shadow: 0px 0px 4px 0px rgba(204, 204, 204, 0.5);
				border-radius: 16rpx;
				margin-bottom: 30rpx;

				.body {
					display: flex;
					flex-wrap: wrap;
					justify-content: space-between;

					text {
						font-size: 32rp;
						 
						margin-top: 20rpx;
					}
				}

				.title {
					display: flex;
					padding: 0 0 30rpx 0;
					border-bottom: #ccc 1px dashed;
					justify-content: space-between;

					text {
						font-size: 36rpx;
						color: #000;
						font-weight: 600;
					}
				}
			}
		}

		.none {
			display: flex;
			flex-direction: column;
			align-items: center;

			image {
				width: 360rpx;
				height: 300rpx;
				margin-bottom: 20rpx;
			}

			text {
				font-size: 32rpx;
				color: #999;
			}

		}
		.btn-box{
			margin-top: 20rpx;
			display: flex;
			justify-content: center;
			.btn-area{
				display: flex;
			}
		}
	}
</style>